﻿using Arch.EntityFrameworkCore.UnitOfWork;
using Microsoft.AspNetCore.Mvc;
using MyTodo.Api.Entities;
using MyTodo.Api.Services.Interfaces;
using MyTodo.Shared.Dtos;
using MyTodo.Shared.Parameters;
using MyTodo.Shared.Services;

namespace MyTodo.Api.Controllers;

/// <summary>
/// 待办事项控制器
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class ToDoController : ControllerBase
{
    private readonly IToDoService _service;

    public ToDoController(IToDoService service)
    {
        _service = service;
    }

    [HttpGet]
    public async Task<ApiResponse> Get(int id) => await _service.GetSingleAsync(id);

    [HttpGet]
    public async Task<ApiResponse> GetAll([FromQuery] QueryParameter parameter) => await _service.GetAllAsync(parameter);

    [HttpPost]
    public async Task<ApiResponse> Add([FromBody] ToDoDto model) => await _service.AddAsync(model);

    [HttpPost]
    public async Task<ApiResponse> Update([FromBody] ToDoDto model) => await _service.UpdateAsync(model);

    [HttpDelete]
    public async Task<ApiResponse> Delete(int id) => await _service.DeleteAsync(id);

}
